#pragma once

#include "CXcpObjectBase.h"
#include "IPALSurface.h"
#include "CXcpObjectThreadSafeAddRefPolicy.h"
#include "CNotifyOnDelete.h"
class HWTextureAtlas;
class AtlasNode;
class HWTextureAtlas;
class CMILMatrix;

class HWTexture : 
	public CXcpObjectBase<IPALSurface,CXcpObjectThreadSafeAddRefPolicy>,
	public CNotifyOnDelete
{

public: 
	static HRESULT Create(HWTextureAtlas * pTextureAtlas, 
		AtlasNode * pAtlasNode, 
		XBOOL includesPadding, 
		XBOOL isStandAlone, 
		XBOOL isOpaque, 
		XBOOL callerManagesGutters, 
		HWTexture * * ppHWTexture);
	void GetTextureData(struct IPALSurface * * ppSource);
	void GetLocalSpaceToAtlasTextureSpaceTransform(const CMILMatrix * pLocalSpaceToHWTextureSpace, CMILMatrix * pLocalSpaceToAtlasTextureSpace);
	XBOOL DoesSizeMatch(struct IPALSurface *);
	XBOOL DoesSizeMatchIncludingPadding(const struct XRECT_WH &);
	HRESULT UpdateTextureFromSoftware(struct IPALSurface * pSourceSurface);
	HRESULT GetSharedAtlasTexture(struct IPALOptimizedGraphicsDevice * pUIThreadDevice, struct IPALSurface * * ppSharedAtlasTexture);
	struct XRECT_WH GetSubrect();
	struct XRECT_WH GetSubrectWithoutPadding();
	HWTextureAtlas * GetAtlas();
	XBOOL IsStandAlone();
	XBOOL IsLost();
	XBOOL HasPadding();
	virtual HRESULT Lock(void * * ppAddress, XINT32 * pnStride, XUINT32 * puWidth, XUINT32 * puHeight, XUINT32 nLOD);
	virtual HRESULT Unlock();
	virtual XUINT32 GetWidth();
	virtual XUINT32 GetHeight();
	virtual XUINT32 GetDisplayWidth();
	virtual XUINT32 GetDisplayHeight();
	virtual XBOOL IsHardwareVideoSurface();
	virtual enum PixelFormat GetPixelFormat();
	virtual XBOOL IsOpaque();
	virtual XUINT32 GetMaxLOD();
	virtual XBOOL HasMIPMapChain();
	virtual void SetIsOpaque(XBOOL fIsOpaque);
	virtual HRESULT AddDirty(const struct XRECT_WH & rcDirty);
	virtual struct IPALGraphicsDevice * GetGraphicsDevice();
	virtual HRESULT Notify(enum XSURFNOTIFY cmd, XUINT32 cbData, XUINT8 * pbData);
	virtual HRESULT UpdateSurface(struct IPALSurfaceUpdate * pSurfaceUpdate, struct XPOINT dstOffset, const struct XRECT_WH & srcRect, XBOOL crossAdapterUpdate);
	virtual HRESULT Flip(struct IPALSurfaceUpdate * pSurfaceUpdate);
	virtual XBOOL HasWhitePixel();
	virtual HRESULT Offer();
	virtual HRESULT Reclaim(XBOOL * pWasDiscarded);
	virtual XBOOL AreResourcesAllocated();
	virtual HRESULT GetNotifyOnDelete(struct CNotifyOnDelete * * ppNotifyOnDelete);
	XUINT32 GetPixelStride();
	XINT32 GetOffsetX();
	XINT32 GetOffsetY();
	HRESULT UnlockRect(const struct XRECT_WH * pRect);
	void MakeOpaque();

private: 
	HWTexture(HWTextureAtlas * pTextureAtlas, AtlasNode * pAtlasNode, XBOOL includesPadding, XBOOL isStandAlone, XBOOL isOpaque, XBOOL callerManagesGutters);
	virtual ~HWTexture();
	void GetTextureView(XFLOAT * pTextureViewOffsetX, XFLOAT * pTextureViewOffsetY, XFLOAT * pTextureViewWidth, XFLOAT * pTextureViewHeight);
	HRESULT UnlockImpl(const struct XRECT_WH * pRect);
	HWTextureAtlas * m_pTextureAtlas;
	AtlasNode * m_pAtlasNode;

	struct {
		XBOOL m_includesPadding:1;
		XBOOL m_isStandAlone:1;
		XBOOL m_isOpaque:1;
		XBOOL m_callerManagesGutters:1;
	};



};